Skip to content

Preserve empty JSON schema object maps#234

Open
chubes4 wants to merge 3 commits into
WordPress:trunkfrom
chubes4:fix-json-schema-object-map-serialization
Open

Preserve empty JSON schema object maps#234
chubes4 wants to merge 3 commits into
WordPress:trunkfrom
chubes4:fix-json-schema-object-map-serialization

Conversation

@chubes4

@chubes4 chubes4 commented May 9, 2026

Copy link
Copy Markdown

Summary

  • Adds a JSON-serializable parameter accessor for FunctionDeclaration that preserves empty JSON Schema object-map fields as {}.
  • Updates FunctionDeclaration::jsonSerialize() to use the safe parameter representation.
  • Updates the shared OpenAI-compatible tool payload builder to use the safe parameter representation when embedding function declarations.

Fixes #233.

Testing

  • vendor/bin/phpunit tests/unit/Tools/DTO/FunctionDeclarationTest.php --filter testJsonSerializationPreservesEmptySchemaObjectMaps
  • vendor/bin/phpunit tests/unit/Providers/OpenAiCompatibleImplementation/AbstractOpenAiCompatibleTextGenerationModelTest.php --filter testPrepareToolsParamPreservesEmptySchemaObjectMaps
  • vendor/bin/phpunit tests/unit/Tools/DTO/FunctionDeclarationTest.php
  • vendor/bin/phpunit tests/unit/Providers/OpenAiCompatibleImplementation/AbstractOpenAiCompatibleTextGenerationModelTest.php
  • composer phpcs
  • composer phpstan

AI assistance

  • AI assistance: Yes
  • Tool(s): OpenCode (GPT-5.5)
  • Used for: Drafted the focused serialization fix and tests from the issue reproduction; Chris remains responsible for review and merge.

@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: chubes4 <extrachill@git.wordpress.org>
Co-authored-by: felixarntz <flixos90@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov

codecov Bot commented May 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.22%. Comparing base (6317042) to head (db2e83e).
⚠️ Report is 7 commits behind head on trunk.

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk     #234      +/-   ##
============================================
+ Coverage     88.12%   88.22%   +0.09%     
- Complexity     1213     1226      +13     
============================================
  Files            60       61       +1     
  Lines          3934     3967      +33     
============================================
+ Hits           3467     3500      +33     
  Misses          467      467              
Flag Coverage Δ
unit 88.22% <100.00%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@felixarntz felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chubes4 Thank you for the PR! Mostly looks good, a few minor things to address.

$tools[] = [
'type' => 'function',
'function' => $functionDeclaration->toArray(),
'function' => $function,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't all this code just the same as this simpler version?

Suggested change
'function' => $function,
$tools[] = [
'type' => 'function',
'function' => $functionDeclaration->jsonSerialize(),

Comment thread src/Tools/DTO/FunctionDeclaration.php Outdated
*
* @return array<string, mixed>|\stdClass|null The JSON-serializable parameters schema.
*/
public function getJsonSerializableParameters()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above, this really shouldn't be a public method. it's oddly specific to be part of a public API, and doesn't seem needed as public anyway.

Comment thread src/Tools/DTO/FunctionDeclaration.php Outdated
* objects even when empty. PHP arrays cannot preserve that distinction
* without casting the empty map before serialization.
*
* @since 0.1.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@since annotations for new code must always use @since n.e.x.t.

/**
* {@inheritDoc}
*
* @since 0.1.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above. also applies throughout the PR.

@chubes4

chubes4 commented Jun 9, 2026

Copy link
Copy Markdown
Author

Thank you! Will fix everything noted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve empty JSON Schema object maps in FunctionDeclaration parameters

2 participants